package com.gyf.bos.dao.impl;

import com.gyf.bos.dao.IStaffDao;
import com.gyf.bos.dao.IUserDao;
import com.gyf.bos.dao.base.BaseDaoImpl;
import com.gyf.bos.model.PageBean;
import com.gyf.bos.model.Staff;
import com.gyf.bos.model.User;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projection;
import org.hibernate.criterion.Projections;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.List;

@Repository
public class StaffDaoImpl extends BaseDaoImpl<Staff> implements IStaffDao {

    @Override
    public void pageQuery(PageBean pb){
        int crrentPage = pb.getCurrentPage();
        int pageSize = pb.getPageSize();

        ////查询的封闭对象

        //1.查询总记录数
        DetachedCriteria criteria = pb.getDetachedCriteria();
        criteria.setProjection(Projections.rowCount());//获取总记录数据,内部会变成sql语句
        List<Long> list = this.getHibernateTemplate().findByCriteria(criteria);
        Long total = list.get(0);
        pb.setTotal(total.intValue());

        //2.查询分页数据
        criteria.setProjection(null);//清除前面的查询条件

        List rows = this.getHibernateTemplate().findByCriteria(criteria,(crrentPage-1)*pageSize,pageSize);
        pb.setRows(rows);
    }
}























































